import pymysql

_db = pymysql.connect(host='www.rishenglaw.cn',
                      port=3306,
                      user='risheng',
                      password='647258qwe',
                      database='risheng')

cursor = _db.cursor()
cursor.execute("show tables")
tables = []
for c in cursor.fetchall():
    tables.append(c[0])

for t in tables:
    print("Alter table " + t)
    try:
        n = cursor.execute("ALTER TABLE %s CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" % t)
    except:
        pass

    print(n)

